package com.mingte.manghe.exception;

import com.alibaba.fastjson.JSONObject;
import com.mingte.manghe.common.ResponseResult;
import com.mingte.manghe.utils.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 定义全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object handleException(Exception e) {
        e.printStackTrace();
        String msg = e.getMessage();
        if (StringUtils.isEmpty(msg)) {
            msg = "服务器出错";
        }
        return ResponseResult.fail(msg);
    }

}
